<?php
	
	include_once "../../php/inc/defines.php";
	include_once "../../php/auth.php";
	include_once "../layout.php";
	include_once "../../php/treenode.php";
	include_once "../../php/formhandler.php";
	
	session_start();
	auth::secure(ADMIN);
	
	$tabs = array("Gestion des examens", "exam.php", "Gestion des &eacute;tudiants", "etu.php", "Directeurs des &eacute;tudes", "dde.php", "Administrateurs", "admin.php", "Recherche", "search.php");
	layout::displayPageHeader($tabs, $tabs[0], TRUE, "treediv1");
	
?>
<div class="arborescence" id="treeViewDiv">
	<?php
		$tree1 = unserialize($_SESSION["examTree1"]);
		treenode::treeToHtml($tree1, ADMIN_1, 4);
		$tree2 = unserialize($_SESSION["examTree2"]);
		treenode::treeToHtml($tree2, ADMIN_2, 4);
	?>
</div>
<div class="content">
	<?php
		
		$nodeTypes[ADMIN_1][0] = "semestres";
		$nodeTypes[ADMIN_1][1] = "UE";
		$nodeTypes[ADMIN_1][2] = "modules";
		$nodeTypes[ADMIN_1][3] = "examens";
		$nodeTypes[ADMIN_2][0] = $nodeTypes[ADMIN_1][0];
		$nodeTypes[ADMIN_2][1] = "parcours";
		$nodeTypes[ADMIN_2][2] = $nodeTypes[ADMIN_1][2];
		$nodeTypes[ADMIN_2][3] = $nodeTypes[ADMIN_1][3];
		if(isset($_GET["nodetype"])) {
			echo "<h1>Gestion des ".$nodeTypes[$_GET["treetype"]][$_GET["nodetype"]]." de \"".$_GET["nodename"]."\"</h1>";
			$fh = new formhandler();
			switch($nodeTypes[$_GET["treetype"]][$_GET["nodetype"]]) {
				case "semestres":
					$fh->getForm("SELECT id_sem, nom_sem FROM ".SEMESTRE_TABLE." WHERE id_form=".$_GET["id"], SEMESTRE_TABLE, array("id_sem", "NULL", false, "", "id_form", $_GET["id"], false, "", "nom_sem", "", true, "Nom"));
					break;
				case "UE":
					$fh->getForm("SELECT id_ue, nom_ue FROM ".UE_TABLE." WHERE id_sem=".$_GET["id"], UE_TABLE, array("id_ue", "NULL", false, "", "id_sem", $_GET["id"], false, "", "nom_ue", "", true, "Nom"));
					break;
				case "parcours":
					$fh->getForm("SELECT id_parcours, nom_parcours FROM ".PARCOURS_TABLE." WHERE id_sem=".$_GET["id"], PARCOURS_TABLE, array("id_parcours", "NULL", false, "", "id_sem", $_GET["id"], false, "", "nom_parcours", "", true, "Nom"));
					break;
				case "modules":
					if($_GET["treetype"] == 0)
						$fh->getForm("SELECT id_module, nom_module FROM ".MODULE_TABLE." WHERE id_ue=".$_GET["id"], MODULE_TABLE, array("id_module", "NULL", false, "", "id_ue", $_GET["id"], false, "", "id_parcours", "NULL", false, "", "nom_module", "", true, "Nom"));
					else
						$fh->getForm("SELECT id_module, nom_module FROM ".MODULE_TABLE." WHERE id_parcours=".$_GET["id"], MODULE_TABLE, array("id_module", "NULL", false, "", "id_ue", "NULL", false, "", "id_parcours", $_GET["id"], false, "", "nom_module", "", true, "Nom"));
					break;
				case "examens":
					$fh->getForm("SELECT id_examen, nom_examen, coefficient FROM ".EXAM_TABLE." WHERE id_module=".$_GET["id"], EXAM_TABLE, array("id_examen", "NULL", false, "", "id_module", $_GET["id"], false, "", "nom_examen", "", true, "Nom", "coefficient", "", true, "Coefficient"));
					break;
			}

		}
		else {
			echo "<h1>Gestion des formations</h1>";
			$fh = new formhandler();
			$fh->getForm("SELECT id_form, nom_form FROM ".FORM_TABLE.";", FORM_TABLE, array("id_form", "NULL", false, "", "nom_form", "", true, "Nom"));
		}
		
	?>
</div>
<?php
	
	layout::displayPageFooter();
	
?>
